//
//  FQBorrowListViewController.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/8/23.
//

import UIKit

class FQBorrowListViewController: BaseViewController,JXSegmentedListContainerViewDataSource, JXSegmentedViewDelegate {
    let segmentedDataSource = JXSegmentedTitleDataSource()
    let segmentedView = JXSegmentedView()
    lazy var listContainerView : JXSegmentedListContainerView = {
        JXSegmentedListContainerView(dataSource: self)
    }()
    var index : Int = 0 {
        didSet {
            segmentedView.defaultSelectedIndex = index
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarType = .light
    }
    
    override func initSubviews() {
        super.initSubviews()
        
        segmentedView.delegate = self
        segmentedView.backgroundColor = .white
        view.addSubview(segmentedView)
        
        segmentedView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(NavigationContentTop)
            make.height.equalTo(50)
        }
        
        segmentedView.listContainer = listContainerView
        view.addSubview(listContainerView)
        
        listContainerView.snp.makeConstraints { make in
            make.bottom.left.right.equalTo(view)
            make.top.equalTo(segmentedView.snp.bottom)
        }
        segmentedDataSource.titleNormalColor = .color153
        segmentedDataSource.titleSelectedColor = .color51
        segmentedDataSource.titleNormalFont = .rSFont(16)
        segmentedDataSource.titleSelectedFont = .rSFont(16)
        segmentedView.dataSource = segmentedDataSource
        
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorHeight = 2
        indicator.indicatorColor = .colorMain
        segmentedView.indicators = [indicator]
        segmentedDataSource.titles = ["申请记录", "待提现", "待还款"]
    }
    
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        segmentedDataSource.titles.count
    }
    
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        let vc = FQBorrowChildListViewController(BorrowChildListType(rawValue: index)!)
        vc.viewController = self
        return vc
    }

    override func setupNavigationItems() {
        super.setupNavigationItems()
        title = "我的借款"
    }
}
